# coding:UTF-8
import os
import time
from django import template
from jseasite_student import settings

register = template.Library()

@register.filter
def static_url(value):
    ts = time.time()
    if not settings.DEBUG:
        static_path = os.path.join(settings.STATIC_ROOT, value.replace("/", os.sep))
        if os.path.isfile(static_path):
            ts = os.stat(static_path).st_mtime
    sp = "?" if "?" not in value else "&"
    return settings.STATIC_URL + value + sp + 'v=%.1f' % ts
